package com.wangshang.general.aftersell.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wangshang.general.aftersell.po.AfterSell;

/**
 * A data access object (DAO) providing persistence and search support for
 * AfterSell entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.wangshang.general.aftersell.po.AfterSell
 * @author MyEclipse Persistence Tools
 */

public class AfterSellDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(AfterSellDAO.class);
	// property constants
	public static final String ADDRESS = "address";
	public static final String TEL = "tel";
	public static final String RESULT = "result";
	public static final String USER_FEEDBACK = "userFeedback";
	public static final String CREATER_ID = "createrId";
	public static final String EXECUTER_ID = "executerId";
	public static final String PLACE_ID = "placeId";
	public static final String PLACE_MASK = "placeMask";
	public static final String USER_IDENTIFY = "userIdentify";
	public static final String SHOP_ORDER_ID = "shopOrderId";
	public static final String HALL_ID = "hallId";

	protected void initDao() {
		// do nothing
	}

	public void save(AfterSell transientInstance) {
		log.debug("saving AfterSell instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(AfterSell persistentInstance) {
		log.debug("deleting AfterSell instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public AfterSell findById(java.lang.String id) {
		log.debug("getting AfterSell instance with id: " + id);
		try {
			AfterSell instance = (AfterSell) getHibernateTemplate().get(
					"com.wangshang.general.aftersell.AfterSell", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(AfterSell instance) {
		log.debug("finding AfterSell instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding AfterSell instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from AfterSell as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByTel(Object tel) {
		return findByProperty(TEL, tel);
	}

	public List findByResult(Object result) {
		return findByProperty(RESULT, result);
	}

	public List findByUserFeedback(Object userFeedback) {
		return findByProperty(USER_FEEDBACK, userFeedback);
	}

	public List findByCreaterId(Object createrId) {
		return findByProperty(CREATER_ID, createrId);
	}

	public List findByExecuterId(Object executerId) {
		return findByProperty(EXECUTER_ID, executerId);
	}

	public List findByPlaceId(Object placeId) {
		return findByProperty(PLACE_ID, placeId);
	}

	public List findByPlaceMask(Object placeMask) {
		return findByProperty(PLACE_MASK, placeMask);
	}

	public List findByUserIdentify(Object userIdentify) {
		return findByProperty(USER_IDENTIFY, userIdentify);
	}

	public List findByShopOrderId(Object shopOrderId) {
		return findByProperty(SHOP_ORDER_ID, shopOrderId);
	}

	public List findByHallId(Object hallId) {
		return findByProperty(HALL_ID, hallId);
	}

	public List findAll() {
		log.debug("finding all AfterSell instances");
		try {
			String queryString = "from AfterSell";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public AfterSell merge(AfterSell detachedInstance) {
		log.debug("merging AfterSell instance");
		try {
			AfterSell result = (AfterSell) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(AfterSell instance) {
		log.debug("attaching dirty AfterSell instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(AfterSell instance) {
		log.debug("attaching clean AfterSell instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static AfterSellDAO getFromApplicationContext(ApplicationContext ctx) {
		return (AfterSellDAO) ctx.getBean("AfterSellDAO");
	}
}